<?php
namespace app\beautiful\logic;
use app\common\model\OrderModel;
use app\common\model\ShopModel;
use app\beautiful\model\setting\SettingSmsModel;
use app\beautiful\logic\LogsLogic;
//平台支付的callback 业务处理响应
class PlatformPaymentRespondLogic {
    
    public static  function respond($orderId){
        if(null !== $order = OrderModel::find($orderId)){
            if($order->type == 1){
                if(null !== $shop = ShopModel::find($order->shop_id)){
                    $t = time();
                    $shop->expire_time = $shop->expire_time < $t ? $t : $shop->expire_time;
                    $shop->expire_time = $shop->expire_time + $order->num * 86400;
                    $shop->type = 2;
                    $shop->save();
                    cache('miniapp_'.$order->shop_id,null); //删除小程序的缓存
                }
            }else if($order->type == 2){
                if(null !== $sms = SettingSmsModel::where('shop_id',$order->shop_id)->find()){
                    $sms->sms_num = $sms->sms_num + $order->num;
                    $sms->save();
                    LogsLogic::smsRecharge($order->shop_id,1,$order->num,$order->price);      
                }
            }
        }
    }
}